package ex;

/**
 * @author xizizzz
 * @description: TODO
 * @date 2021-9-7下午 05:59
 */
public class AB {
    static class TreeNode {
        TreeNode left;
        TreeNode right;
        int value = 0;

        public TreeNode(int i) {
            this.value = i;
        }
    }

    public boolean isSub(TreeNode A, TreeNode B) {
        return (A != null && B != null) && (rec(A, B) || isSub(A.left, B) || isSub(A.right, B));
    }

    public boolean rec(TreeNode A, TreeNode B) {
        if (B == null) {
            return true;
        }
        if (A == null || A.value != B.value) {
            return false;
        }
        return rec(A.left, B.left) && rec(A.right, B.right);
    }

}
